package com.cbn.ibcp.jishiting.gs.cms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cbn.ibcp.common.annotation.DataSource;
import com.cbn.ibcp.common.enums.DataSourceType;
import com.cbn.ibcp.jishiting.gs.cms.domain.CpAlbum;
import com.cbn.ibcp.jishiting.gs.cms.enums.OssInjectStatusEnum;
import com.cbn.ibcp.jishiting.gs.cms.mapper.CpAlbumMapper;
import com.cbn.ibcp.jishiting.gs.cms.service.ICpAlbumService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Objects;

@Service
@RequiredArgsConstructor
public class CpAlbumServiceImpl implements ICpAlbumService {

    private final CpAlbumMapper cpAlbumMapper;

    @DataSource(DataSourceType.gs_cms)
    @Override
    public Integer getTotalCreateInjectStatisticDate_5m(Date startDate, Date endDate) {
        LambdaQueryWrapper<CpAlbum> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.between(CpAlbum::getCreateTime, startDate, endDate);
        return cpAlbumMapper.selectCount(queryWrapper);
    }

    @DataSource(DataSourceType.gs_cms)
    @Override
    public Integer getTotalCreateInjectSuccessStatisticDate_5m(Date startDate, Date endDate) {
        LambdaQueryWrapper<CpAlbum> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.between(CpAlbum::getCreateTime, startDate, endDate);
        queryWrapper.eq(CpAlbum::getOssInjectStatus, OssInjectStatusEnum.INJECT_SUCCESS.getCode());
        return cpAlbumMapper.selectCount(queryWrapper);
    }

    @DataSource(DataSourceType.gs_cms)
    @Override
    public Integer getTotalUpdateInjectStatisticDate_5m(Date startDate, Date endDate) {
        LambdaQueryWrapper<CpAlbum> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.between(CpAlbum::getModifyTime, startDate, endDate);
        return cpAlbumMapper.selectCount(queryWrapper);
    }

    @DataSource(DataSourceType.gs_cms)
    @Override
    public Integer getTotalUpdateInjectSuccessStatisticDate_5m(Date startDate, Date endDate) {
        LambdaQueryWrapper<CpAlbum> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.between(CpAlbum::getModifyTime, startDate, endDate);
        queryWrapper.eq(CpAlbum::getOssInjectStatus, OssInjectStatusEnum.INJECT_SUCCESS.getCode());
        return cpAlbumMapper.selectCount(queryWrapper);
    }


    @DataSource(DataSourceType.gs_cms)
    @Override
    public CpAlbum selectById(Long id) {
        if (Objects.isNull(id)) {
            return null;
        }
        return cpAlbumMapper.selectById(id);
    }
}
